<?php
function init()
{
  //这里需要使用类的反射
  $ctl = empty($_GET['ctl'])?"":$_GET['ctl'];
  if($ctl=="")throw new Exception("/ctl/index.php--------Controller name error");
  $ctl = "Controller".$ctl;
  include_once($ctl.".php");
  $class = new ReflectionClass($ctl);
  $ctl = $class->newInstance();
  $ac = !isset($_GET['ac'])?"defaultAction":trim($_GET['ac']);
  if(!method_exists($ctl,$ac))
  $ac = "defaultAction";
  //默认验证
  $method = $class->getMethod("before_all_action");
  //判断是否有拦截验证
  if(property_exists($ctl,"before_action"))
  {
    $handleAction = $ctl->before_action;
    if(!empty($handleAction))
    if(is_array($handleAction))
    {
      if(array_key_exists($ac,$handleAction))
      if(method_exists($ctl,$handleAction[$ac]))
      {
        $method = $class->getMethod($handleAction[$ac]);
      }
    }
  }
  $method->invoke($ctl);
  $method = $class->getMethod($ac);
  $method->invoke($ctl);
  //判断是否有执行后的操作
  //默认验证
  $method = $class->getMethod("after_all_action");
  //判断是否有拦截验证
  if(property_exists($ctl,"after_action"))
  {
    $handleAction = $ctl->after_action;
    if(!empty($handleAction))
    if(is_array($handleAction))
    {
      if(array_key_exists($ac,$handleAction))
      if(method_exists($ctl,$handleAction[$ac]))
      $method = $class->getMethod($handleAction[$ac]);
    }
  }
  $method->invoke($ctl);
}
//开始执行
try
{  
  init();
}
catch(Exception $ex)
{
  echo $ex->getMessage();
}
 ?>